package com.wanmait.recruitment.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.recruitment.mapper.ConfigMapper;
import com.wanmait.recruitment.pojo.Config;
import com.wanmait.recruitment.service.ConfigService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class ConfigServiceImpl implements ConfigService {
    @Resource
    private ConfigMapper configMapper;
    @Override
    public String getValueByKey(String key) {
        return configMapper.getValueByKey(key);
    }

    @Override
    public String getDefaultValueByKey(String key) {
        return configMapper.getDefaultValueByKey(key);
    }

    @Override
    @Cacheable("configCache")
    public PageInfo<Config> findAllConfig(Config config, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Config> configs = configMapper.findAll(config);
        PageInfo<Config> pageInfo = new PageInfo<>(configs);
        return pageInfo;
    }

    @Override
    public void insert(Config object) {

    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(String ids) {

    }

    @Override
    @CacheEvict(value = "configCache",allEntries = true)
    public void update(Config object) {
        configMapper.updateByPrimaryKeySelective(object);
    }

    @Override
    public Config findById(Integer id) {

        return configMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Config> findAll() {
        return null;
    }

    @Override
    public List<Config> findAll(Config object) {
        return null;
    }

    @Override
    public PageInfo<Config> findPage(int pageNum, int pageSize) {
        return null;
    }
}
